<!DOCTYPE html>
<html lang="en">
<link rel="stylesheet" href="/stylesheets/style.css">
<head>
    <meta charset="UTF-8">
    <title>我是开发模板</title>
</head>
<body>
<h1>我是开发模板</h1>
<button onclick="testAjax()">测试Ajax</button>
</body>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script>
    function testAjax() {
        // $.get("/api/search", {'keyword': '金馆长', 'mime': '0', 'page': 0}, function (data) {
        //         alert("Data Loaded: " + JSON.stringify(data));
        //     }
        // );
        // $.get('api/search?keyword=金馆长&mime=0&page=2',function (data) {
        //     alert("Data Loaded: " + JSON.stringify(data));
        // });
        $.post("/api/search",{'keyword':'金馆长','mime':0,'page':2},function (data) {
            alert("Data Loaded: " + JSON.stringify(data));
        });
        $.ajax({
            url : "/api/search",
            type : "POST",
            contentType: "application/json;charset=utf-8",
            data : JSON.stringify({'keyword':'金馆长','mime':0,'page':2}),
            success : function(result) {
                alert("Data Loaded: " + JSON.stringify(result));
            },
            error:function(msg){
                alert("Data Loaded: " + JSON.stringify(msg));
            }
        });
        // $.get('https://www.doutula.com/api/search?keyword=金馆长&mime=0&page=2',function (data) {
        //     alert("Data Loaded: " + JSON.stringify(data));
        // });
        var params = "{\n" +
            "            \"password\": \"123456\", \"restNo\": \"89000\", \"username\": \"555\",\n" +
            "            \"sn\": \"EAE29DFC7DF0ED4C804C584AB7A81E4D\"\n" +
            "            , \"timestamp\": 1548416898\n" +
            "        }";
        var pam = {
            "password": "123456", "restNo": "89000", "username": "555", "sn": "EAE29DFC7DF0ED4C804C584AB7A81E4D"
            , "timestamp": 1547027057735
        };
        $.ajax(
            {
                url: '/dish-api/api/v1/login',
                data: JSON.stringify(pam),
                type: 'POST',
                processData: false,
                contentType: 'application/json', //typically 'application/x-www-form-urlencoded', but the service you are calling may expect 'text/json'... check with the service to see what they expect as content-type in the HTTP header.
                success: function (msg) {
                    alert("Data Loaded: " + JSON.stringify(msg));
                }
            }
        );
        // $.ajax("/dish-api/api/v1/login",{
        //     'data': JSON.stringify(pam), //{action:'x',params:['a','b','c']}
        //     'type': 'POST',
        //     'processData': false,
        //     'contentType': 'application/json' //typically 'application/x-www-form-urlencoded', but the service you are calling may expect 'text/json'... check with the service to see what they expect as content-type in the HTTP header.
        // });
        // $.ajax({
        //     url: "/dish-api/api/v1/login",
        //     type: "POST",
        //     data: params,
        //     dataType: "json",
        //     anysc: false,
        //     contentType: "application/json,charset=utf-8",
        //     success: function(data) {
        //         alert("Data Loaded: " + JSON.stringify(data));
        //     },
        //     error: function(xhr) {
        //         console.log(xhr);
        //     }
        // });

        // $.get("/dish-api/api/v1/login", {"password":"123456","restNo":"89000","username":"555","sn":"EAE29DFC7DF0ED4C804C584AB7A81E4D"
        //         ,"timestamp":1547027057735},
        //     function (data) {
        //         alert("Data Loaded: " + JSON.stringify(data));
        //     });
    }
</script>
</html>